﻿using System;
using System.IO;

namespace crawler
{
    /// <summary>
    /// Singleton class.
    /// </summary>
    class Logger
    {
        private string FileName { get; set; }

        private const string directoryName = "Logs";

        private static Logger instance;

        public static Logger getLogger()
        {
            if (instance == null)
            {
                instance = new Logger();
            }
            return instance;
        }

        private Logger()
        {
            if (Directory.Exists(directoryName) == false)
            {
                Directory.CreateDirectory(directoryName);
            }
            DateTime now = DateTime.Now;
            FileName = directoryName + "\\" + now.ToString("yyyy-MM-dd-HH-mm-ss") + ".txt";
        }

        public void log(String text)
        {
            text = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss ") + text;
            using (StreamWriter file = new StreamWriter(FileName, true))
            {
                file.WriteLine(text);
            }
            Console.WriteLine(text);
        }

    }
}
